<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Request;
use think\facade\Config;//引入配置
use TCPDF;
use Elasticsearch\ClientBuilder;

class Esq extends Base
{   

   public function index(Request $request){
     $post=request()->post();
     if(!empty($post['shu'])){
         $day=date("Y-m-d",time());
         $dang=Db::connect('publicdata')->table('lily_searchcount')->where([['shu','=',$post['shu']],['create_time','like','%'.$day.'%'],['ip','=',$this->base_data['ip']]])->select();
         if(empty($dang)&&$this->base_data['ip']!='222.64.21.2'){
            $data=array();
            foreach ($post as $key => $value) {
               if(!empty($value)&&$value!=''){
                  $data[$key]=trim($value);
               }
            }
            $shibieip="https://apis.map.qq.com/ws/location/v1/ip?ip=".$this->base_data['ip']."&key=O4DBZ-LI26I-BEPGW-56A6T-FJNLZ-F4BWP";
            $loaction=json_decode(file_get_contents($shibieip),true);
            if($loaction['status']==0){
               $country=$loaction['result']['ad_info']['nation'];
            }else{
               $country="未能识别";
            }

            $data['create_time']=date('Y-m-d h:i:s',time());
            $data['ip']=$this->base_data['ip'];
            $data['sys']=$_SERVER['HTTP_USER_AGENT'];
            $data['country']=$country;
            if($country!='缅甸'){   
               Db::connect('publicdata')->table('lily_searchcount')->insert($data);
            }
         }
     }
     
   }
}